package com.lhm.dao;


import com.lhm.entity.MyMatter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

@Repository
public class MatterDao {

    @Autowired
    MongoTemplate mongoTemplate;

    //添加
    public MyMatter addMatter(MyMatter matter){
        MyMatter matter1 = mongoTemplate.save(matter);
        return matter1;
    }

    //根据id查询
    public MyMatter findById(String id){
        MyMatter matter = mongoTemplate.findById(id, MyMatter.class);
        return matter;
    }

    //删除
    public void delById(String id){
        Query query = new Query(Criteria.where("id").is(id));
        mongoTemplate.findAndRemove(query,MyMatter.class);
    }

}
